//----------------------------------------------------------------------------
//
// TSDuck - The MPEG Transport Stream Toolkit
// Copyright (c) 2005-2025, Thierry Lelegard
// BSD-2-Clause license, see LICENSE.txt file or https://tsduck.io/license
//
//----------------------------------------------------------------------------
//
//  TSUnit test suite for class ts::Zlib.
//
//----------------------------------------------------------------------------

#include "tsZlib.h"
#include "tsNullReport.h"
#include "tsCerrReport.h"
#include "tsunit.h"


//----------------------------------------------------------------------------
// The test fixture
//----------------------------------------------------------------------------

class ZlibTest: public tsunit::Test
{
    TSUNIT_DECLARE_TEST(Reference1);
    TSUNIT_DECLARE_TEST(Reference4);
    TSUNIT_DECLARE_TEST(Reference9);
    TSUNIT_DECLARE_TEST(AllLevels);
    TSUNIT_DECLARE_TEST(Specific);

private:
    bool verify(const ts::ByteBlock& data, size_t start = 0);
    ts::Report& report();
};

TSUNIT_REGISTER(ZlibTest);


//----------------------------------------------------------------------------
// Reference data
//----------------------------------------------------------------------------

namespace {
    const char intext[] =
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor "
        "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud "
        "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure "
        "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "
        "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit "
        "anim id est laborum.\n"
        "Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque "
        "laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto "
        "beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, "
        "aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione "
        "voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit "
        "amet consectetur adipisci[ng] velit, sed quia non numquam [do] eius modi tempora inci[di]dunt, "
        "ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam,"
        "quis nostrum[d] exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea "
        "commodi consequatur? [D]Quis autem vel eum i[r]ure reprehenderit, qui in ea voluptate velit "
        "esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?\n"
        "At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti "
        "atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, "
        "similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. "
        "Et harum quidem reru[d]um facilis est e[r]t expedita distinctio. Nam libero tempore, cum soluta "
        "nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat facere possimus, "
        "omnis voluptas assumenda est, omnis dolor repellend[a]us. Temporibus autem quibusdam "
        "et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae "
        "sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, "
        "ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.";

    constexpr size_t intext_size = sizeof(intext) - 1;

    // Level 1, input size: 2204, output size: 1065
    const ts::ByteBlock reference_1 {
        0x78, 0x01, 0x75, 0x95, 0xCD, 0x8A, 0x23, 0x37, 0x10, 0xC7, 0xEF, 0xFB, 0x14, 0xF5, 0x00, 0xC6,
        0xAF, 0xB0, 0x04, 0x76, 0x0F, 0x81, 0x10, 0x08, 0x49, 0x4E, 0xC6, 0x07, 0x59, 0x5D, 0xE3, 0x29,
        0x68, 0xB5, 0x7A, 0xF4, 0x31, 0xCC, 0xE3, 0xEF, 0xAF, 0x24, 0xDB, 0x3B, 0x26, 0xD9, 0x8B, 0x71,
        0xB7, 0xAA, 0x55, 0xAA, 0xFF, 0x97, 0xFE, 0xC8, 0x45, 0x93, 0xD8, 0x5E, 0x7B, 0x92, 0x25, 0xAF,
        0xB9, 0x48, 0xB5, 0x26, 0x21, 0x69, 0x3B, 0x48, 0xCC, 0x5B, 0xD5, 0xD8, 0xB4, 0xF5, 0x22, 0x61,
        0xB1, 0xDD, 0x6A, 0xB4, 0xED, 0x2A, 0xBA, 0x1A, 0x8B, 0x55, 0x17, 0x3E, 0x10, 0xB5, 0x5E, 0x53,
        0x5E, 0xA4, 0x69, 0xDA, 0xF9, 0xD8, 0xB6, 0x68, 0x8B, 0x2D, 0x7D, 0x6B, 0xD2, 0x9B, 0xAC, 0xE1,
        0xC2, 0xF6, 0xA2, 0x6D, 0x6E, 0xAD, 0x92, 0xC2, 0x75, 0x0B, 0x12, 0x56, 0x7B, 0xEB, 0xE1, 0x28,
        0xFF, 0x36, 0xD1, 0xCD, 0x12, 0x7B, 0x4B, 0x32, 0xFF, 0xF3, 0xCE, 0x63, 0x48, 0x07, 0x79, 0xEB,
        0x56, 0x65, 0xCB, 0xB5, 0x95, 0xBE, 0x88, 0x7E, 0x68, 0x89, 0xD6, 0x42, 0xB3, 0xBC, 0x49, 0x5F,
        0xD7, 0x90, 0x62, 0x9E, 0x3B, 0x7B, 0x91, 0x55, 0xF3, 0x4E, 0x63, 0x4B, 0xDB, 0x29, 0x16, 0x0D,
        0x1C, 0x3C, 0x71, 0xA6, 0x3C, 0x07, 0xA0, 0x55, 0x3B, 0xCA, 0x37, 0xDF, 0x32, 0xF4, 0xA6, 0x62,
        0xA5, 0x73, 0xA6, 0x39, 0xAB, 0x6D, 0x52, 0x74, 0x2F, 0xFA, 0xAA, 0xDB, 0xA2, 0x85, 0xC1, 0x79,
        0xF1, 0x9E, 0xD7, 0xBE, 0xD3, 0x4E, 0x39, 0x0E, 0x93, 0x8A, 0xD6, 0xAA, 0x12, 0x6D, 0x5D, 0xEF,
        0x08, 0x31, 0x50, 0x97, 0x97, 0x7E, 0xB5, 0xD0, 0x64, 0xF3, 0x03, 0xC9, 0x1E, 0x0A, 0x0F, 0xBD,
        0x1C, 0xE5, 0xFB, 0x47, 0xD4, 0xBD, 0x29, 0x80, 0x55, 0x03, 0x83, 0x1C, 0x63, 0xD0, 0x48, 0x5D,
        0xEC, 0xBB, 0x2D, 0x81, 0x5D, 0x19, 0x6B, 0x93, 0xBD, 0x64, 0x5B, 0x74, 0x73, 0x14, 0x1D, 0x29,
        0x9A, 0xC6, 0xBE, 0xEE, 0xC1, 0xE7, 0x96, 0xFC, 0xF2, 0x62, 0xD1, 0x82, 0x2C, 0x5A, 0xB5, 0xF8,
        0x6A, 0xCA, 0xAB, 0x1F, 0x23, 0x38, 0x40, 0x06, 0x1C, 0xF5, 0x86, 0x6B, 0x4F, 0xC7, 0x2F, 0x7F,
        0x43, 0x02, 0xD3, 0xEF, 0x5A, 0xEA, 0xEE, 0x5F, 0x35, 0xAB, 0x07, 0xE9, 0xCC, 0x22, 0x39, 0x01,
        0x8D, 0x58, 0x65, 0x8C, 0x8D, 0xA3, 0x55, 0xD1, 0x52, 0x6E, 0xE4, 0x3E, 0x06, 0x04, 0xF9, 0x18,
        0x7B, 0x0D, 0x5B, 0xB3, 0xC7, 0x6C, 0xE9, 0xAD, 0x2B, 0xE8, 0xF6, 0x65, 0xBE, 0x3D, 0x48, 0xCB,
        0x2D, 0x24, 0x50, 0xA2, 0x98, 0x36, 0xD0, 0x03, 0xC0, 0x5E, 0x83, 0x64, 0x82, 0x33, 0x15, 0x54,
        0xC2, 0x45, 0x80, 0x27, 0x33, 0x07, 0x04, 0x36, 0x67, 0xFC, 0xDD, 0xC1, 0xF4, 0xD3, 0x38, 0xF7,
        0xD4, 0x40, 0x52, 0x28, 0xF1, 0xD5, 0x1A, 0x72, 0xCA, 0x72, 0x51, 0x90, 0xA0, 0x88, 0x12, 0x88,
        0xB0, 0xD8, 0xC2, 0xC0, 0xE1, 0x00, 0x7B, 0xFB, 0x6A, 0x11, 0xD1, 0x1C, 0xE5, 0x4F, 0x4D, 0x88,
        0x6B, 0xCC, 0x4C, 0x23, 0xA4, 0x71, 0x67, 0x65, 0xCA, 0x23, 0xDC, 0x5F, 0x54, 0xD7, 0xEB, 0x41,
        0x42, 0xE5, 0x70, 0x3E, 0x28, 0x4A, 0x05, 0x90, 0xBC, 0x38, 0x62, 0xFC, 0x71, 0x9A, 0x6E, 0x62,
        0x05, 0x5C, 0x57, 0x06, 0x92, 0x7E, 0xEB, 0xE0, 0x4A, 0xA5, 0xAB, 0xD1, 0x6E, 0xD2, 0xE4, 0xA4,
        0x19, 0xEC, 0x9C, 0x81, 0x32, 0xA4, 0xC6, 0xF9, 0x1E, 0x2D, 0x11, 0xBB, 0x2F, 0x6C, 0x8A, 0x01,
        0xF8, 0xF4, 0xC0, 0x3F, 0x87, 0x00, 0xC1, 0x97, 0xEC, 0x9F, 0x54, 0x46, 0x04, 0x97, 0xCA, 0x8A,
        0xD7, 0x0D, 0x6D, 0xDD, 0x5D, 0x35, 0x5E, 0x41, 0xE7, 0x93, 0xB7, 0xFE, 0xD7, 0x5A, 0xA7, 0xED,
        0x7A, 0x9E, 0x9A, 0x9B, 0xEE, 0x62, 0xAB, 0x30, 0xE4, 0xB2, 0x75, 0x58, 0xA1, 0xC1, 0x69, 0xC9,
        0xE7, 0x61, 0x38, 0x34, 0xB1, 0xD8, 0xCD, 0x72, 0x61, 0x78, 0xEE, 0xB4, 0xD8, 0xD9, 0x5D, 0x07,
        0xFB, 0xBF, 0xB2, 0x1D, 0x04, 0x0E, 0xDF, 0x25, 0x27, 0x44, 0x19, 0xF2, 0xD3, 0x80, 0xFF, 0xF5,
        0x22, 0x00, 0x4F, 0x33, 0xFA, 0x78, 0x37, 0x2F, 0xA6, 0xD3, 0x42, 0xFF, 0x4F, 0x76, 0x64, 0xC6,
        0x61, 0x48, 0xC6, 0x29, 0x80, 0x41, 0x61, 0xED, 0x40, 0xB4, 0x03, 0xFE, 0xB0, 0xBE, 0x65, 0xA8,
        0x03, 0xAD, 0x27, 0x93, 0xBA, 0xA3, 0x7F, 0x9A, 0xD4, 0xEE, 0x94, 0x38, 0x77, 0x5F, 0xE5, 0xF4,
        0xED, 0xFC, 0xD7, 0xDD, 0xA9, 0x9E, 0x07, 0x2B, 0x5E, 0x43, 0xF6, 0xA7, 0x72, 0x76, 0xD3, 0x3E,
        0x79, 0x75, 0x62, 0x8D, 0x77, 0x30, 0xFC, 0x83, 0xAA, 0x89, 0xDF, 0xF0, 0xAC, 0xAF, 0x03, 0xDA,
        0x66, 0xAF, 0xB6, 0xBA, 0x89, 0xA0, 0xC7, 0xD0, 0xDB, 0x4D, 0x01, 0xDE, 0xEE, 0x30, 0x1A, 0x0C,
        0x67, 0x3F, 0x13, 0xE7, 0x3D, 0xA7, 0xC1, 0xFD, 0x7D, 0xBE, 0x6F, 0x0F, 0x0E, 0x4F, 0x76, 0xFF,
        0xFA, 0xE5, 0x37, 0x40, 0x54, 0x34, 0x80, 0x76, 0x5C, 0xE9, 0xD3, 0x4E, 0xC9, 0xDD, 0x86, 0xAB,
        0x7B, 0x45, 0xEB, 0x10, 0x95, 0xD1, 0x38, 0x42, 0xAB, 0xD5, 0x12, 0x65, 0x4B, 0x8F, 0x46, 0xC5,
        0x6C, 0x78, 0x59, 0xC3, 0x86, 0x54, 0x0D, 0xE4, 0xF6, 0x12, 0x70, 0xFC, 0xB4, 0xE2, 0x7D, 0x1C,
        0x77, 0xA5, 0xAE, 0xF0, 0xD0, 0xF0, 0x4F, 0x73, 0xC9, 0x01, 0x74, 0x21, 0x9D, 0x6C, 0x9C, 0x8B,
        0xCD, 0x5C, 0x55, 0xFA, 0x70, 0xD9, 0x63, 0x4C, 0xDE, 0x8C, 0x20, 0xEA, 0xC5, 0x46, 0x10, 0x1D,
        0x24, 0x5F, 0x66, 0x12, 0x81, 0xB7, 0x47, 0x91, 0xBB, 0x93, 0x64, 0x98, 0x59, 0xF4, 0x7E, 0x0F,
        0x23, 0x4B, 0xE6, 0x12, 0xD1, 0xE7, 0x58, 0x9A, 0x47, 0xFD, 0x45, 0x2E, 0x21, 0x51, 0x4F, 0x26,
        0x0E, 0xF4, 0x9C, 0x4D, 0x8F, 0xD0, 0x9F, 0x50, 0x92, 0xF6, 0xDF, 0x9B, 0xBC, 0x86, 0xC2, 0x23,
        0x8A, 0x5A, 0x50, 0x4E, 0x21, 0xDE, 0x10, 0x94, 0xAF, 0x07, 0xE2, 0xD5, 0xB3, 0x82, 0x68, 0x53,
        0xA8, 0xE6, 0xF7, 0x63, 0x57, 0x3F, 0x23, 0xC8, 0xC1, 0xDA, 0x16, 0xC9, 0x7E, 0x22, 0x01, 0x36,
        0x57, 0xBB, 0x38, 0xDE, 0xF3, 0xB6, 0x51, 0xAE, 0x28, 0x3E, 0xAF, 0xF8, 0x94, 0xD2, 0x2D, 0x5F,
        0xEE, 0x7B, 0xAC, 0x76, 0x25, 0xD0, 0xC9, 0x52, 0x90, 0xCA, 0xA3, 0xC8, 0x87, 0x9A, 0x4A, 0xB0,
        0x34, 0xB6, 0x9E, 0xC4, 0x72, 0xED, 0x40, 0x96, 0x2D, 0xE3, 0x89, 0x5B, 0x28, 0x7C, 0x58, 0xC2,
        0xD7, 0x6B, 0x88, 0x44, 0x94, 0x9F, 0x4B, 0x51, 0xDD, 0x9E, 0x9D, 0x3A, 0xA7, 0x6C, 0x86, 0xEA,
        0x8D, 0x1D, 0xAE, 0x93, 0xCA, 0xAD, 0x49, 0xA3, 0x30, 0xAD, 0x3F, 0x57, 0xA7, 0xD1, 0x51, 0xAA,
        0xAE, 0x30, 0xB7, 0x9C, 0xC2, 0xB9, 0xD7, 0xA3, 0xFC, 0x33, 0xAE, 0x47, 0xBB, 0xD0, 0xCD, 0x2F,
        0xA1, 0x01, 0x02, 0x0F, 0x8B, 0xC7, 0xC6, 0x4C, 0xAA, 0x89, 0x2F, 0x13, 0x2C, 0x7A, 0x81, 0xEF,
        0x51, 0x37, 0x30, 0x42, 0xC2, 0x1A, 0xB9, 0x84, 0x46, 0xA0, 0xFA, 0x06, 0x35, 0xB0, 0xB9, 0xA8,
        0xFB, 0xD3, 0x6F, 0x69, 0x0C, 0xCF, 0x16, 0x77, 0xC9, 0x20, 0x06, 0x7A, 0xF7, 0xC5, 0x10, 0x16,
        0x6A, 0x1F, 0xB7, 0x10, 0xCB, 0x3F, 0xF5, 0xEF, 0x9C, 0x17, 0x1D, 0xB1, 0x4F, 0xC1, 0x51, 0x7E,
        0x6F, 0x23, 0xCE, 0x75, 0x50, 0xE3, 0x9C, 0x24, 0x79, 0xB5, 0x08, 0xC2, 0xDB, 0xBC, 0xF7, 0x69,
        0xB7, 0x1B, 0xBA, 0x24, 0xA9, 0x91, 0x62, 0xE4, 0x2A, 0x19, 0x2D, 0x3D, 0x5C, 0x8B, 0x72, 0xE7,
        0x38, 0xD0, 0xF5, 0xD1, 0x7E, 0x4C, 0x98, 0x82, 0x0D, 0x55, 0x92, 0x37, 0xA1, 0x7E, 0x36, 0xDC,
        0x88, 0x64, 0x82, 0xFA, 0x05, 0x58, 0xC7, 0x67, 0x03, 0xAC, 0x89, 0x8A, 0x07, 0xF8, 0xFC, 0x6C,
        0x62, 0xC7, 0xA5, 0xFD, 0x03, 0x13, 0x6A, 0x36, 0x47,
    };

    // Level 4, input size: 2204, output size: 1017
    const ts::ByteBlock reference_4 {
        0x78, 0x5E, 0x75, 0x55, 0x4B, 0x6E, 0x23, 0x39, 0x0C, 0xDD, 0xF7, 0x29, 0x78, 0x00, 0xC3, 0x57,
        0x68, 0x0C, 0xD0, 0xBD, 0x18, 0x60, 0xD0, 0xC0, 0x60, 0x66, 0x56, 0x86, 0x17, 0xB4, 0xC4, 0x38,
        0x04, 0x4A, 0xA5, 0x8A, 0x3E, 0x41, 0x8E, 0xDF, 0xEF, 0x49, 0x65, 0xC7, 0x46, 0x4F, 0x6F, 0x82,
        0x54, 0x95, 0x44, 0xF2, 0xFD, 0xE8, 0xBF, 0x72, 0xB1, 0x24, 0xBE, 0xD5, 0x9E, 0x24, 0xE6, 0x25,
        0x17, 0xA9, 0xDE, 0x44, 0x93, 0xB5, 0x83, 0x84, 0xBC, 0x56, 0x0B, 0xCD, 0x5A, 0x2F, 0xA2, 0xD1,
        0x37, 0xAF, 0xC1, 0xD7, 0xAB, 0xD8, 0xE2, 0xF8, 0x58, 0x2D, 0xE2, 0x82, 0x98, 0xF7, 0x9A, 0x72,
        0x94, 0x66, 0x69, 0xC3, 0x65, 0x5F, 0x83, 0x47, 0x8F, 0x7D, 0x6D, 0xD2, 0x9B, 0x2C, 0x7A, 0x41,
        0x79, 0xB1, 0x36, 0x4B, 0x9B, 0x24, 0xBD, 0xAE, 0x2A, 0xBA, 0xF8, 0x5B, 0xD7, 0xA3, 0xFC, 0xD7,
        0xC4, 0x56, 0x4F, 0xA8, 0x2D, 0xC9, 0xF9, 0xCF, 0x3B, 0x1E, 0x35, 0x1D, 0xE4, 0xAD, 0x7B, 0x95,
        0x35, 0xD7, 0x56, 0x7A, 0x14, 0xFB, 0xB0, 0x12, 0xBC, 0x69, 0xF3, 0xBC, 0x4A, 0x5F, 0x16, 0x4D,
        0x21, 0xCF, 0xCA, 0x3C, 0xE4, 0xD5, 0xD9, 0x69, 0x94, 0xF4, 0x0D, 0x87, 0xC5, 0x14, 0x83, 0x27,
        0xCC, 0x94, 0x27, 0x00, 0xB4, 0x6A, 0x47, 0xF9, 0xC6, 0x92, 0xDA, 0x9B, 0x89, 0x97, 0x8E, 0x49,
        0x26, 0x56, 0x5F, 0xA5, 0xD8, 0x56, 0xEC, 0xD5, 0xD6, 0x68, 0x05, 0xC0, 0xF1, 0xE2, 0x3D, 0x2F,
        0x7D, 0x43, 0x3B, 0xC3, 0x38, 0x40, 0x2A, 0x56, 0xAB, 0x49, 0xF0, 0x65, 0xB9, 0x31, 0x04, 0x40,
        0x5D, 0x5E, 0xFA, 0xD5, 0xB5, 0xC9, 0xCA, 0x81, 0x64, 0xD3, 0x82, 0x87, 0x5E, 0x8E, 0xF2, 0xFD,
        0x23, 0xD8, 0xD6, 0xAC, 0x93, 0x46, 0x70, 0x90, 0x43, 0x50, 0x0B, 0x38, 0x17, 0xFA, 0xE6, 0x51,
        0x1B, 0x6F, 0x00, 0xC5, 0x56, 0xB2, 0x47, 0x5B, 0xC9, 0x22, 0x99, 0x42, 0xD3, 0xD0, 0x97, 0x4D,
        0x89, 0x5B, 0xF2, 0xCB, 0x8B, 0x07, 0x57, 0x89, 0x56, 0xAD, 0xF0, 0x6B, 0xCA, 0x0B, 0xC7, 0x50,
        0x12, 0xE4, 0xA0, 0xA3, 0xEE, 0xBC, 0xF6, 0x74, 0xFC, 0xF2, 0x0F, 0x44, 0x00, 0xFA, 0xCD, 0x4A,
        0xDD, 0x78, 0xAB, 0x79, 0x3D, 0x48, 0x07, 0x16, 0xC9, 0x09, 0xD4, 0x88, 0x57, 0xC0, 0x58, 0x31,
        0x5A, 0x15, 0x2B, 0x65, 0x17, 0xF7, 0x0E, 0x10, 0xCC, 0x87, 0xD0, 0xAB, 0xAE, 0xCD, 0xEF, 0xD8,
        0xD2, 0x5B, 0x37, 0xD4, 0xEF, 0x71, 0xBE, 0x3D, 0x48, 0xCB, 0x4D, 0x93, 0xD0, 0x24, 0x8A, 0x36,
        0x90, 0x07, 0x04, 0xF3, 0x0C, 0x2C, 0xA3, 0x54, 0x4A, 0x4D, 0xF4, 0x22, 0xA0, 0x27, 0x03, 0x07,
        0x04, 0x6C, 0x24, 0xE8, 0x9D, 0x64, 0x72, 0x1A, 0x6A, 0x8F, 0x33, 0x10, 0x49, 0x4B, 0x78, 0xF5,
        0x06, 0x3B, 0x65, 0xB9, 0x18, 0x98, 0xC0, 0x21, 0xE7, 0xDF, 0xE8, 0xA1, 0xE9, 0xE0, 0xE1, 0x00,
        0xF5, 0xB6, 0xC5, 0x03, 0xC0, 0x1D, 0xE5, 0x87, 0xA5, 0x3C, 0xDD, 0xC1, 0x46, 0xE9, 0x61, 0xE8,
        0x61, 0x0F, 0xBD, 0xBD, 0xA8, 0x84, 0x74, 0x10, 0xAD, 0x18, 0x8E, 0x40, 0x0B, 0x45, 0x96, 0x1C,
        0xC9, 0x18, 0xFE, 0xA1, 0x4C, 0xBB, 0x59, 0xC7, 0xAD, 0xDD, 0x11, 0xE8, 0x86, 0x93, 0x74, 0xA3,
        0xEF, 0xB8, 0x31, 0x69, 0xAE, 0xA3, 0xB4, 0x94, 0x61, 0x35, 0x7B, 0xE4, 0x89, 0x77, 0x5C, 0x56,
        0x43, 0x00, 0xC6, 0xA0, 0xAB, 0x91, 0x02, 0x18, 0xBE, 0xE4, 0x61, 0x56, 0x40, 0x4C, 0x54, 0x66,
        0x16, 0xD8, 0x99, 0x9C, 0xA9, 0xDA, 0xC7, 0x7D, 0xCE, 0xD6, 0xFF, 0x46, 0xEB, 0xB4, 0x5E, 0xCF,
        0xD3, 0x73, 0x0F, 0x03, 0xD3, 0x2E, 0x6B, 0x4F, 0xA3, 0xC1, 0x29, 0xE6, 0xF3, 0x08, 0x1C, 0x3C,
        0x11, 0x7D, 0x8F, 0x9C, 0x8E, 0xCC, 0x9D, 0xA2, 0x9F, 0x99, 0xBA, 0xC3, 0xEF, 0x63, 0x97, 0xF6,
        0xDC, 0xA5, 0x21, 0x1A, 0x40, 0x3E, 0x00, 0xFC, 0x35, 0x8B, 0x7A, 0x0B, 0xE3, 0x43, 0x16, 0xD3,
        0x29, 0x9E, 0x9F, 0xE2, 0x08, 0x8C, 0x23, 0x90, 0x80, 0x53, 0xB6, 0x91, 0xC7, 0xDA, 0x01, 0x64,
        0xF3, 0x7D, 0x06, 0xCF, 0x95, 0x71, 0x7E, 0x0E, 0x29, 0x13, 0xFD, 0x19, 0x52, 0xFF, 0x0C, 0x69,
        0x2F, 0x5F, 0xE5, 0xF4, 0xED, 0xFC, 0xF7, 0x2D, 0xA9, 0xDC, 0x07, 0x0B, 0xB2, 0x06, 0x22, 0x4F,
        0xE5, 0xCC, 0xD0, 0x3E, 0x65, 0x75, 0x72, 0x8D, 0xEC, 0xD8, 0xDD, 0x0C, 0x4F, 0x99, 0x1D, 0xE6,
        0x4C, 0x68, 0xFE, 0xEA, 0x0B, 0x43, 0x04, 0x79, 0x1C, 0x7E, 0x7B, 0x68, 0x77, 0x18, 0x0D, 0x46,
        0xB2, 0x9F, 0x85, 0x63, 0xCF, 0x19, 0x70, 0xBE, 0xCF, 0x9F, 0x5E, 0x7B, 0x8E, 0xFB, 0xD7, 0x2F,
        0x7F, 0x34, 0x5A, 0x3D, 0xD3, 0x3B, 0xA4, 0x7B, 0xC6, 0x29, 0x31, 0x6D, 0x48, 0x75, 0xAF, 0xF0,
        0x3A, 0x10, 0x66, 0x78, 0x1C, 0x46, 0xAB, 0xD5, 0x13, 0x8E, 0xC5, 0x1E, 0x1C, 0x27, 0x66, 0xC3,
        0xCB, 0xA2, 0x2B, 0xAC, 0xEA, 0x40, 0xBC, 0x15, 0x45, 0xE2, 0x67, 0x14, 0x6F, 0x70, 0x98, 0x4A,
        0x5B, 0xA0, 0x43, 0x43, 0x7E, 0x1A, 0x2D, 0x07, 0xA2, 0x0B, 0x3E, 0xF9, 0x98, 0xAB, 0x7E, 0x7A,
        0x77, 0xA6, 0xEC, 0x0E, 0x13, 0x6F, 0xC6, 0x22, 0xEA, 0xC5, 0xC7, 0x22, 0x3A, 0x48, 0xBE, 0xCC,
        0x4D, 0xE4, 0x73, 0x15, 0x51, 0x40, 0xBB, 0xED, 0xA2, 0xF7, 0xDB, 0x32, 0xF2, 0xE4, 0x94, 0xC8,
        0x9E, 0xD7, 0xD2, 0x1C, 0xF5, 0x37, 0x7B, 0x09, 0x6F, 0xB8, 0x99, 0x30, 0xD0, 0xF3, 0x6E, 0xBA,
        0xBB, 0x6F, 0x52, 0x89, 0x6D, 0xFF, 0xBD, 0xC9, 0xAB, 0xF2, 0x91, 0x1E, 0x30, 0xAE, 0x94, 0xD2,
        0x61, 0x28, 0x7E, 0x57, 0xAC, 0x57, 0xEE, 0x0A, 0x5C, 0x37, 0x48, 0xDD, 0xB8, 0x08, 0x8C, 0x33,
        0x82, 0x39, 0xC0, 0x59, 0x03, 0xCC, 0x86, 0x95, 0x00, 0x35, 0x17, 0xBF, 0x90, 0xEF, 0x69, 0x7D,
        0x48, 0x1C, 0x70, 0xBD, 0x82, 0xAD, 0xC6, 0xA4, 0x5C, 0x6E, 0x35, 0x16, 0xBF, 0xC2, 0x24, 0x98,
        0x19, 0x4C, 0xE5, 0x71, 0x88, 0xA0, 0xA6, 0x13, 0x3C, 0x8D, 0xD2, 0x53, 0x58, 0x58, 0x1D, 0x62,
        0x79, 0x1C, 0x4F, 0x70, 0xBE, 0x7E, 0x78, 0x42, 0xAE, 0x17, 0x0D, 0x58, 0x51, 0x9C, 0xCB, 0x0A,
        0x63, 0x4E, 0xE9, 0x28, 0xD9, 0x5C, 0xAA, 0x77, 0x37, 0x68, 0x45, 0xBE, 0xD1, 0x48, 0x67, 0xF4,
        0xE7, 0xD7, 0x19, 0x74, 0x38, 0xD5, 0x16, 0x28, 0x17, 0x4F, 0x7A, 0xEE, 0xF5, 0x28, 0xFF, 0x8E,
        0x81, 0xFD, 0xD2, 0x6F, 0xD6, 0x06, 0x09, 0x78, 0x88, 0x5C, 0x1B, 0x73, 0x53, 0x4D, 0x7E, 0x59,
        0xC0, 0x2E, 0xCE, 0xCD, 0xC9, 0x97, 0xE4, 0x08, 0x16, 0xB6, 0x00, 0x43, 0x8F, 0xCC, 0xB1, 0x40,
        0x55, 0x14, 0x17, 0x63, 0x3E, 0xF9, 0x2B, 0x8D, 0x63, 0xF6, 0x90, 0xE5, 0xCA, 0xDE, 0x3D, 0x3A,
        0x8C, 0x05, 0xB7, 0x8F, 0x5F, 0x21, 0x1B, 0x62, 0xED, 0xFE, 0xA7, 0xE6, 0xC5, 0xC6, 0xDA, 0xC7,
        0x81, 0xA3, 0xFC, 0xD9, 0xC6, 0x3A, 0xB7, 0x21, 0xCD, 0xEC, 0xF7, 0xEA, 0x01, 0x0C, 0xAF, 0x73,
        0x39, 0xA1, 0xDD, 0xE6, 0xB0, 0x87, 0x0D, 0x2B, 0x86, 0x46, 0x1E, 0x98, 0xE5, 0x31, 0x1D, 0x26,
        0x26, 0xD1, 0x77, 0x4E, 0xE6, 0x80, 0x49, 0x7D, 0xB8, 0x12, 0x79, 0x07, 0x4B, 0x0F, 0x81, 0x1B,
        0xB7, 0xB0, 0xA8, 0x5F, 0x40, 0xEB, 0xB8, 0x36, 0xC8, 0x9A, 0xAC, 0x70, 0x81, 0xCF, 0x6B, 0x93,
        0x3B, 0xFC, 0x68, 0xFF, 0x04, 0x13, 0x6A, 0x36, 0x47,
    };

    // Level 9, input size: 2204, output size: 1007
    const ts::ByteBlock reference_9 {
        0x78, 0xDA, 0x7D, 0x55, 0x4B, 0x6E, 0x23, 0x47, 0x0C, 0xDD, 0xCF, 0x29, 0x78, 0x00, 0x41, 0x57,
        0x18, 0x04, 0x98, 0x59, 0x04, 0x18, 0x0C, 0x10, 0x24, 0x59, 0x09, 0x5A, 0x50, 0x55, 0xB4, 0x4C,
        0xA0, 0x3E, 0xED, 0xFA, 0x18, 0x3E, 0x7E, 0x1E, 0x59, 0x2D, 0x59, 0x42, 0x26, 0xD9, 0x18, 0xEE,
        0xEE, 0x2A, 0x92, 0xEF, 0x47, 0xFD, 0xA8, 0x4D, 0x32, 0xE9, 0xD6, 0x67, 0xA6, 0x58, 0x53, 0x6D,
        0xD4, 0x75, 0x10, 0x67, 0x19, 0x07, 0x0A, 0xB5, 0x74, 0x09, 0x43, 0xC6, 0x6C, 0xC4, 0x51, 0x37,
        0xED, 0x41, 0xCB, 0x95, 0x24, 0x29, 0x3E, 0x76, 0x89, 0xB8, 0x40, 0xA2, 0xB3, 0xE7, 0x1A, 0x69,
        0x48, 0xDE, 0x70, 0x59, 0x4B, 0xD0, 0xA8, 0x71, 0x96, 0x41, 0x73, 0x50, 0xE2, 0x0B, 0xCA, 0x93,
        0x8C, 0x55, 0x5A, 0x28, 0xF3, 0xB5, 0x30, 0x71, 0xD2, 0xB7, 0xC9, 0x47, 0xFA, 0x7B, 0x90, 0x14,
        0xCD, 0xA8, 0x4D, 0x59, 0xED, 0x9F, 0x77, 0x3C, 0x72, 0x3E, 0xD0, 0xDB, 0xD4, 0x4E, 0xA5, 0xF6,
        0xD1, 0x66, 0x24, 0xF9, 0x90, 0x16, 0x74, 0xF0, 0xD0, 0x5A, 0x68, 0xA6, 0xC4, 0x39, 0xD4, 0x55,
        0xD9, 0x0E, 0x69, 0x57, 0xEB, 0xE4, 0x25, 0x75, 0xC3, 0x61, 0x12, 0xC6, 0xE0, 0x19, 0x33, 0xD5,
        0x05, 0x00, 0xAD, 0xC6, 0x91, 0xBE, 0x59, 0x49, 0x9E, 0x43, 0x48, 0xDB, 0xC4, 0x24, 0x0B, 0xAB,
        0x16, 0x6A, 0xB2, 0x35, 0x79, 0x95, 0x12, 0xA5, 0x01, 0x38, 0x5E, 0xBC, 0xD7, 0x34, 0x37, 0xB4,
        0x13, 0x8C, 0x03, 0xA4, 0x24, 0xBD, 0x0B, 0x05, 0x4D, 0xE9, 0xC6, 0x10, 0x00, 0x4D, 0x7A, 0x99,
        0x57, 0xE5, 0x41, 0xC5, 0x06, 0xA2, 0x8D, 0x1B, 0x1E, 0x66, 0x3B, 0xD2, 0xF7, 0x8F, 0x20, 0xDB,
        0x90, 0x69, 0x34, 0x82, 0x83, 0x1A, 0x02, 0x4B, 0xC0, 0xB9, 0x30, 0x37, 0x8D, 0x3C, 0xEC, 0x06,
        0x50, 0x6C, 0xAD, 0x6A, 0x94, 0x62, 0x2C, 0x1A, 0x53, 0x68, 0x1A, 0x66, 0xDA, 0xD8, 0x70, 0x53,
        0x7D, 0x79, 0xD1, 0xA0, 0x4C, 0x51, 0xBA, 0x34, 0xFB, 0x9A, 0x6B, 0xB2, 0x31, 0xD8, 0x08, 0x52,
        0xD0, 0xD1, 0x77, 0x5E, 0x67, 0x3E, 0x7E, 0xF9, 0x13, 0x22, 0x00, 0xFD, 0x26, 0xAD, 0x6F, 0x76,
        0x6B, 0x68, 0x3F, 0xD0, 0x04, 0x16, 0xAA, 0x19, 0xD4, 0x90, 0x76, 0xC0, 0x28, 0x18, 0xAD, 0x93,
        0xB4, 0xB6, 0x8B, 0x7B, 0x07, 0x08, 0xE6, 0x43, 0x98, 0x9D, 0xCB, 0xD0, 0x3B, 0xB6, 0xFC, 0x36,
        0x05, 0xF5, 0x67, 0x5C, 0x6F, 0x0F, 0x34, 0xEA, 0xE0, 0x4C, 0x66, 0x12, 0x46, 0x1B, 0xC8, 0x03,
        0x82, 0xED, 0x0C, 0x2C, 0xC3, 0xA6, 0x14, 0x0B, 0xF1, 0x85, 0x40, 0x4F, 0x05, 0x0E, 0x08, 0x38,
        0x8C, 0xA0, 0x77, 0x23, 0xD3, 0xA6, 0x31, 0xED, 0x71, 0x06, 0x22, 0x71, 0x0B, 0xAF, 0x3A, 0x60,
        0xA7, 0x4A, 0x17, 0x01, 0x13, 0x38, 0xA4, 0xF6, 0x37, 0x6A, 0x18, 0xEC, 0x3C, 0x1C, 0xA0, 0xDE,
        0x96, 0x34, 0x00, 0xDC, 0x91, 0x7E, 0x4A, 0xAE, 0xCB, 0x1D, 0xD6, 0x28, 0x3F, 0x0C, 0xED, 0xF6,
        0xE0, 0xDB, 0x8B, 0x6E, 0x90, 0x0E, 0xC4, 0x1D, 0xC3, 0x19, 0xD0, 0x66, 0x22, 0x53, 0x8D, 0xC6,
        0x18, 0xFE, 0x31, 0x99, 0x76, 0xB3, 0xFA, 0xAD, 0xDD, 0x11, 0xE8, 0x86, 0x93, 0xE6, 0x46, 0xDD,
        0x71, 0x63, 0xD2, 0xDA, 0xBD, 0x34, 0x35, 0xB7, 0x9A, 0x3C, 0xF2, 0x64, 0x77, 0x94, 0x8A, 0x20,
        0x00, 0x3E, 0x68, 0x11, 0xA3, 0x00, 0x86, 0x6F, 0xD5, 0xCD, 0x0A, 0x88, 0xD9, 0x94, 0x59, 0x05,
        0x76, 0x26, 0x57, 0xAA, 0xF6, 0x71, 0x9F, 0xB3, 0xF5, 0xCB, 0x68, 0x9D, 0xCA, 0xF5, 0xBC, 0x3C,
        0xF7, 0x30, 0xB0, 0xD9, 0xA5, 0xCC, 0xEC, 0x0D, 0x4E, 0xB1, 0x9E, 0x3D, 0x70, 0xF0, 0x44, 0xD4,
        0x3D, 0x72, 0xEC, 0x99, 0x3B, 0x45, 0x3D, 0x47, 0x1F, 0xED, 0x3F, 0x63, 0x97, 0xF7, 0xDC, 0x65,
        0x17, 0x0D, 0x20, 0x1F, 0x00, 0xFE, 0x3B, 0x8B, 0x7C, 0x0B, 0xE3, 0x43, 0x16, 0xF3, 0x29, 0x9E,
        0x9F, 0xE2, 0x08, 0x8C, 0x1E, 0x48, 0xC0, 0x69, 0x9B, 0xE7, 0xB1, 0x4F, 0x00, 0xD9, 0x74, 0x9F,
        0x41, 0x6B, 0xB7, 0x38, 0x3F, 0x87, 0x34, 0x3E, 0x85, 0x54, 0x3F, 0x43, 0x3A, 0xDB, 0x57, 0x3A,
        0x7D, 0x3B, 0xFF, 0x71, 0x4B, 0xAA, 0xED, 0x83, 0x84, 0xAC, 0x81, 0xC8, 0x53, 0x3B, 0x5B, 0x68,
        0x9F, 0xB2, 0xBA, 0xB8, 0x46, 0x76, 0x84, 0x7F, 0x99, 0x59, 0x37, 0x67, 0x46, 0xF3, 0x57, 0x4D,
        0x16, 0x22, 0xC8, 0xA3, 0xF0, 0xDB, 0x43, 0xBB, 0x83, 0x37, 0xF0, 0x64, 0x3F, 0x0B, 0x67, 0x3D,
        0x57, 0xC0, 0xED, 0x7D, 0xFD, 0xF4, 0xDA, 0x73, 0xDC, 0xBF, 0x7E, 0xF9, 0x6D, 0x98, 0xD5, 0xAB,
        0x79, 0xC7, 0xE8, 0x5E, 0x71, 0xCA, 0xD3, 0x1F, 0xA0, 0x13, 0xBC, 0x0E, 0x84, 0x15, 0x1E, 0x87,
        0xD1, 0x7A, 0xD7, 0x8C, 0x63, 0x71, 0x06, 0xC5, 0x89, 0xD5, 0xF0, 0x92, 0xB8, 0xC0, 0xAA, 0x0A,
        0xC4, 0x5B, 0x63, 0x24, 0x7E, 0x45, 0xF1, 0x06, 0xC7, 0x52, 0x29, 0x09, 0x3A, 0x0C, 0xE4, 0x67,
        0x98, 0xE5, 0x40, 0x74, 0xC3, 0x27, 0xF5, 0xB9, 0xFA, 0xA7, 0x77, 0x57, 0xCA, 0xEE, 0x30, 0xF1,
        0xC6, 0x17, 0xD1, 0x6C, 0xEA, 0x8B, 0xE8, 0x40, 0xF5, 0xB2, 0x36, 0x91, 0xAE, 0x55, 0xA4, 0x4E,
        0xD6, 0xBE, 0x8B, 0xDE, 0x6F, 0xCB, 0x48, 0xB3, 0x9A, 0x44, 0xF2, 0xBC, 0x96, 0x0E, 0xFF, 0xB7,
        0x97, 0xF0, 0xC6, 0x36, 0x13, 0x06, 0x7A, 0xDE, 0x4D, 0x77, 0xF7, 0x2D, 0x2A, 0xB1, 0xED, 0xBF,
        0x0F, 0x7A, 0x65, 0x7B, 0x34, 0x0F, 0x88, 0xAD, 0x94, 0x36, 0x61, 0x28, 0xFB, 0xCE, 0x58, 0xAF,
        0xB6, 0x2B, 0x70, 0x5D, 0x20, 0xF5, 0xB0, 0x45, 0x20, 0x36, 0x23, 0x98, 0x03, 0x9C, 0x12, 0x60,
        0x36, 0xAC, 0x04, 0xA8, 0x99, 0xF4, 0x62, 0x7C, 0x2F, 0xEB, 0x43, 0xE2, 0x80, 0xEB, 0x1D, 0x6C,
        0x0D, 0x4B, 0xCA, 0xE5, 0x56, 0x23, 0xE9, 0x15, 0x26, 0xC1, 0xCC, 0x60, 0xAA, 0xFA, 0x21, 0x03,
        0xB5, 0x9C, 0xA0, 0xD9, 0x4B, 0x2F, 0x61, 0x61, 0x75, 0x88, 0xA5, 0xD1, 0x9F, 0xE0, 0x7C, 0xFE,
        0xD0, 0x8C, 0x5C, 0x27, 0x0E, 0x58, 0x51, 0x36, 0x97, 0x34, 0x8B, 0xB9, 0x49, 0x67, 0x92, 0xAD,
        0xA5, 0x7A, 0x77, 0x03, 0x77, 0xE4, 0x1B, 0x8D, 0x78, 0x45, 0x7F, 0x7D, 0x5D, 0x41, 0x87, 0x53,
        0x25, 0x41, 0xB9, 0x78, 0xE2, 0xF3, 0xEC, 0x47, 0xFA, 0xCB, 0x07, 0xD6, 0xCB, 0xBC, 0x59, 0x1B,
        0x24, 0xE0, 0x21, 0xB2, 0x13, 0xE5, 0x2B, 0xCB, 0xF9, 0xB5, 0x02, 0x72, 0xD1, 0xB1, 0x22, 0xE0,
        0x1C, 0xC1, 0xC2, 0x12, 0x60, 0x68, 0xCF, 0x9C, 0x15, 0xE8, 0x8C, 0xE2, 0x24, 0x96, 0x4F, 0x59,
        0x81, 0x97, 0x87, 0x2C, 0x77, 0xEB, 0x3D, 0xA3, 0xC2, 0x58, 0x70, 0xBB, 0xFF, 0x0A, 0xC9, 0x78,
        0xF0, 0xBF, 0x69, 0xDE, 0xC4, 0xD7, 0x3E, 0x0E, 0x1C, 0xE9, 0xF7, 0xE1, 0xEB, 0x5C, 0x5C, 0x9A,
        0xD5, 0xEF, 0x55, 0x03, 0x18, 0x2E, 0x6B, 0x39, 0xA1, 0xDD, 0xA6, 0xB0, 0x87, 0xB8, 0x15, 0xC3,
        0x30, 0x1E, 0xE6, 0xD8, 0xA7, 0xC3, 0xC4, 0x46, 0xF4, 0x9D, 0x93, 0x35, 0x60, 0x66, 0x75, 0x57,
        0x22, 0xEF, 0x60, 0xE9, 0x21, 0x70, 0x7E, 0x0B, 0x8B, 0xFA, 0x05, 0xB4, 0xFA, 0x35, 0x27, 0x6B,
        0xB1, 0x62, 0x0B, 0x7C, 0x5D, 0x5B, 0xDC, 0xE1, 0x47, 0xFB, 0x1F, 0x13, 0x6A, 0x36, 0x47,
    };
}


//----------------------------------------------------------------------------
// Debug report
//----------------------------------------------------------------------------

ts::Report& ZlibTest::report()
{
    if (tsunit::Test::debugMode()) {
        CERR.setMaxSeverity(ts::Severity::Debug);
        return CERR;
    }
    else {
        return NULLREP;
    }
}


//----------------------------------------------------------------------------
// Verify decrypted data.
//----------------------------------------------------------------------------

bool ZlibTest::verify(const ts::ByteBlock& data, size_t start)
{
    if (data.size() == start + intext_size && ::memcmp(data.data() + start, intext, intext_size) == 0) {
        return true;
    }
    else {
        size_t diff = 0;
        while (start + diff < data.size() && diff < intext_size && data[start + diff] == uint8_t(intext[diff])) {
            diff++;
        }
        debug() << "ZlibTest: invalid decompressed data, decompressed size: " << (data.size() - start)
                << ", reference size: " << intext_size << ", first diff at index " << diff << std::endl;
        return false;
    }
}


//----------------------------------------------------------------------------
// Unitary tests.
//----------------------------------------------------------------------------

TSUNIT_DEFINE_TEST(Reference1)
{
    ts::ByteBlock out;
    TSUNIT_ASSERT(ts::Zlib::Decompress(out, reference_1, report()));
    TSUNIT_ASSERT(verify(out));

    if (!ts::Zlib::DefaultSdefl() && ts::Zlib::SdeflSupported()) {
        TSUNIT_ASSERT(ts::Zlib::Decompress(out, reference_1, report(), true));
        TSUNIT_ASSERT(verify(out));
    }
}

TSUNIT_DEFINE_TEST(Reference4)
{
    ts::ByteBlock out;
    TSUNIT_ASSERT(ts::Zlib::Decompress(out, reference_4, report()));
    TSUNIT_ASSERT(verify(out));

    if (!ts::Zlib::DefaultSdefl() && ts::Zlib::SdeflSupported()) {
        TSUNIT_ASSERT(ts::Zlib::Decompress(out, reference_4, report(), true));
        TSUNIT_ASSERT(verify(out));
    }
}

TSUNIT_DEFINE_TEST(Reference9)
{
    ts::ByteBlock out;
    TSUNIT_ASSERT(ts::Zlib::Decompress(out, reference_9, report()));
    TSUNIT_ASSERT(verify(out));

    if (!ts::Zlib::DefaultSdefl() && ts::Zlib::SdeflSupported()) {
        TSUNIT_ASSERT(ts::Zlib::Decompress(out, reference_9, report(), true));
        TSUNIT_ASSERT(verify(out));
    }
}

TSUNIT_DEFINE_TEST(AllLevels)
{
    for (int level = 0; level <= 9; level++) {
        debug() << "ZlibTest::AllLevels: testing level " << level << std::endl;

        ts::ByteBlock compressed;
        TSUNIT_ASSERT(ts::Zlib::Compress(compressed, intext, intext_size, level, report()));

        ts::ByteBlock out;
        TSUNIT_ASSERT(ts::Zlib::Decompress(out, compressed, report()));
        TSUNIT_ASSERT(verify(out));

        out.clear();
        out.appendUInt32(0x12345678);
        TSUNIT_ASSERT(ts::Zlib::DecompressAppend(out, compressed, report()));
        TSUNIT_ASSERT(out.size() > 4);
        TSUNIT_EQUAL(0x12345678, ts::GetUInt32(out.data()));
        TSUNIT_ASSERT(verify(out, 4));

        if (!ts::Zlib::DefaultSdefl() && ts::Zlib::SdeflSupported()) {
            out.clear();
            TSUNIT_ASSERT(ts::Zlib::Decompress(out, compressed, report(), true));
            TSUNIT_ASSERT(verify(out));

            out.clear();
            out.appendUInt32(0x12345678);
            TSUNIT_ASSERT(ts::Zlib::DecompressAppend(out, compressed, report(), true));
            TSUNIT_ASSERT(out.size() > 4);
            TSUNIT_EQUAL(0x12345678, ts::GetUInt32(out.data()));
            TSUNIT_ASSERT(verify(out, 4));
        }

        compressed.clear();
        compressed.appendUInt32(0x12345678);
        TSUNIT_ASSERT(ts::Zlib::CompressAppend(compressed, intext, intext_size, level, report()));
        TSUNIT_ASSERT(compressed.size() > 4);
        TSUNIT_EQUAL(0x12345678, ts::GetUInt32(compressed.data()));

        out.clear();
        TSUNIT_ASSERT(ts::Zlib::Decompress(out, compressed.data() + 4, compressed.size() - 4, report()));
        TSUNIT_ASSERT(verify(out));

        if (!ts::Zlib::DefaultSdefl() && ts::Zlib::SdeflSupported()) {
            compressed.clear();
            TSUNIT_ASSERT(ts::Zlib::Compress(compressed, intext, intext_size, level, report(), true));

            out.clear();
            TSUNIT_ASSERT(ts::Zlib::Decompress(out, compressed, report(), true));
            TSUNIT_ASSERT(verify(out));

            compressed.clear();
            compressed.appendUInt32(0x12345678);
            TSUNIT_ASSERT(ts::Zlib::CompressAppend(compressed, intext, intext_size, level, report(), true));
            TSUNIT_ASSERT(compressed.size() > 4);
            TSUNIT_EQUAL(0x12345678, ts::GetUInt32(compressed.data()));

            out.clear();
            TSUNIT_ASSERT(ts::Zlib::Decompress(out, compressed.data() + 4, compressed.size() - 4, report(), false));
            TSUNIT_ASSERT(verify(out));
        }
    }
}

TSUNIT_DEFINE_TEST(Specific)
{
    ts::ByteBlock in;
    in.reserve(256 * 50);
    for (int val = 0; val < 256; val++) {
        for (int count = 50; count > 0; count--) {
            in.push_back(uint8_t(val));
        }
    }
    debug() << "ZlibTest::Specific: in size: " << in.size() << std::endl;

    ts::ByteBlock compressed;
    TSUNIT_ASSERT(ts::Zlib::Compress(compressed, in, 1, report()));
    debug() << "ZlibTest::Specific: compressed size: " << compressed.size() << std::endl;

    ts::ByteBlock decompressed;
    TSUNIT_ASSERT(ts::Zlib::Decompress(decompressed, compressed, report()));
    debug() << "ZlibTest::Specific: decompressed size: " << decompressed.size() << std::endl;
    TSUNIT_ASSERT(decompressed == in);

    if (!ts::Zlib::DefaultSdefl() && ts::Zlib::SdeflSupported()) {
        decompressed.clear();
        TSUNIT_ASSERT(ts::Zlib::Decompress(decompressed, compressed, report(), true));
        debug() << "ZlibTest::Specific: sdefl decompressed size: " << decompressed.size() << std::endl;
        TSUNIT_ASSERT(decompressed == in);

        compressed.clear();
        TSUNIT_ASSERT(ts::Zlib::Compress(compressed, in, 1, report(), true));
        debug() << "ZlibTest::Specific: sdefl compressed size: " << compressed.size() << std::endl;

        decompressed.clear();
        TSUNIT_ASSERT(ts::Zlib::Decompress(decompressed, compressed, report(), true));
        debug() << "ZlibTest::Specific: sdefl decompressed size: " << decompressed.size() << std::endl;
        TSUNIT_ASSERT(decompressed == in);

        decompressed.clear();
        TSUNIT_ASSERT(ts::Zlib::Decompress(decompressed, compressed, report(), false));
        debug() << "ZlibTest::Specific: zlib decompressed size: " << decompressed.size() << std::endl;
        TSUNIT_ASSERT(decompressed == in);
    }
}
